//
//  MediaListCell.m
//  YUXiu
//
//  Created by wang on 16/6/25.
//  Copyright © 2016年 Wang. All rights reserved.
//

#import "MediaListCell.h"

@interface MediaListCell ()
@property(nonatomic,strong) UIImageView *mdImg;
@property(nonatomic,strong) UILabel *title;
@property(nonatomic,strong) UILabel *address;
@property(nonatomic,strong) UILabel *author;
@property(nonatomic,strong) UILabel *stateLabel;
@property(nonatomic,strong) UILabel *numStudy;

@end

@implementation MediaListCell
//100
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //
        _mdImg = [[UIImageView alloc]initWithFrame:krect(10, 10, 110, 80)];
        _mdImg.layer.cornerRadius = 5;
        _mdImg.layer.masksToBounds = YES;
        [self.contentView addSubview:_mdImg];
        
        _stateLabel = [[UILabel alloc]initWithFrame:krect(kScreenWidth-55, 10, 45, 25)];
        _stateLabel.backgroundColor = kGrayCOLOR;
        _stateLabel.textColor = kWhiteCOLOR;
        _stateLabel.layer.cornerRadius = 4;
        _stateLabel.layer.masksToBounds = YES;
        _stateLabel.font = Font(12);
        _stateLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_stateLabel];
        
        _title = [[UILabel alloc]init];
//        _title.backgroundColor = kRedCOLOR;//
        _title.textColor = kBlackCOLOR;
        _title.font = Font(14);
        
        //添加约束
        [self.contentView addSubview:_title];
        [_title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_mdImg.mas_right).with.offset(0);
            make.right.equalTo(_stateLabel.mas_left).with.offset(0);
            make.height.equalTo(@(30));
            make.top.equalTo(_mdImg.mas_top).with.offset(-5);
        }];
        
        _address = [[UILabel alloc]init];
//        _address.backgroundColor = kOrangeCOLOR;
        _address.textColor = kLightGrayCOLOR;
        _address.font = Font(12);
        [self.contentView addSubview:_address];
        [_address mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_mdImg.mas_right).with.offset(0);
            make.right.equalTo(_stateLabel.mas_left).with.offset(0);
            make.height.equalTo(@(20));
            make.top.equalTo(_title.mas_bottom).with.offset(-5);
        }];
        
        _numStudy = [[UILabel alloc]initWithFrame:krect(kScreenWidth-100, _mdImg.golf_bottom-20, 90, 20)];
        _numStudy.textColor = kGrayCOLOR;
        _numStudy.textAlignment = NSTextAlignmentRight;
        _numStudy.font = Font(12);
        [self.contentView addSubview:_numStudy];
        
        _author = [[UILabel alloc] init];
        _author.textColor = kLightGrayCOLOR;
        _author.font = Font(12);
        [self.contentView addSubview:_author];
        
        [_author mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_mdImg.mas_right).with.offset(0);
            make.right.equalTo(_numStudy.mas_left).with.offset(0);
            make.height.equalTo(@(20));
            make.centerY.equalTo(_numStudy);
            
        }];
        UIView *line = [[UIView alloc]initWithFrame:krect(3, 99, kScreenWidth-6, 1)];
        line.backgroundColor = kLightGrayCOLOR;
        [self.contentView addSubview:line];

        
        
    }
    
    
    return self;
}


-(void)layoutSubviews{
    [_mdImg setImage:[UIImage imageNamed:@"nopoto160x200"]];
    _stateLabel.text = @"回放";
    [_title setText:@"课程合集名称"];
    [_address setText:@"深圳市"];
    [_numStudy setText:@"8080人学习过"];
            NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:@"作者:江北一刀溜"];
            //    染色的range
            NSRange redRange = NSMakeRange(3, noteStr.length-3);
            [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
            [_author setAttributedText:noteStr] ;

    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
